﻿create or replace function addressListLoad(xml)
returns xml as
$$
declare
begin

return
  
	xmlelement(name addresslist, (
	xmlelement(name addresslist, 
			(select xmlagg(addressCol) from (
						 select 
						 xmlelement( name address, xmlattributes(asse.idaddress as id), 
						 xmlelement(name addressname, asse.nameaddress)) addressCol
						 from addresstable asse) as tab)
					)
		   )
		    );

end;
$$ language plpgsql stable;